﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DiagrammInternalStructure.Exceptions;

namespace DiagrammInternalStructure
{
    public partial class ClassElement : AtomicInstance
    {

        private static string[] m_basicTypesKeys = {"object", "void", "int", "float", "double", "char", "string", "bool"};
        private static Dictionary<string, ClassElement> m_basicTypes = null;

        private static short m_basicTypesCreated = -1;

        public static void CreateBasicTypes()
        {
            if (m_basicTypesCreated == -1)
            {
                m_basicTypesCreated = 0;
                m_basicTypes = new Dictionary<string, ClassElement>();
                Dictionary<string, ClassElement> result = new Dictionary<string, ClassElement>();
                foreach (string str in m_basicTypesKeys)
                {
                    ClassElement ce = new ClassElement(str, ProtectionType.PublicType, null);
                    if (str == "void")
                    {
                        ce.m_final = true;
                    }
                    if (str == "object")
                    {
                        ce.m_base = null;
                    }
                    else
                    {
                        ce.m_base = result["object"];
                    }
                    result.Add(str, ce);
                }

                m_basicTypes = result;
                m_basicTypesCreated = 1;
            }
        }


        private static void CheckingBasicTypes()
        {
            if (m_basicTypesCreated == -1)
            {
                throw new BasicTypesNotCreatedException();
            }
        }

        public static ClassElement Void
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["void"];
            }
        }


        public static ClassElement Int
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["int"];
            }
        }

        public static ClassElement Float
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["float"];
            }
        }

        public static ClassElement Double
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["double"];
            }
        }

        public static ClassElement Char
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["char"];
            }
        }

        public static ClassElement String
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["string"];
            }
        }

        public static ClassElement Bool
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["bool"];
            }
        }

        public static ClassElement Object
        {
            get
            {
                CheckingBasicTypes();
                return m_basicTypes["object"];
            }
        }
    }
}